<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
class CheckBox extends codexForms
{
    function CheckBox($name,$params) { 
        codexForms::initiate($name,$params);
    }

    function prepForDb ($value){ 
        if(array_key_exists($this->name,$_POST))
            return 'yes';
        else{
            return '';
        }
    }

    function in_arrayr($needle, $haystack) {
            foreach ($haystack as $v) {
                    if ($needle == $v) return true;
                    elseif (is_array($v)) return $this->in_arrayr($needle, $v);
            }
            return false;
    }

    function prepForDisplay($value){
        if(!empty($value))
            return $this->label;
        else 
            return '';
    }

	function getHTML()
	{
        $html = $this->prefix;
        $html .= $this->getMessage($this->name);
        $html .= '
            <label for="'.$this->name.'">
                '.$this->label.'
            </label>
            <input type="checkbox" value="1" 
        '; 
        if($this->value == true) 
            $html .= 'checked'; 

        $html.='
            name="'.$this->name.'" '.$this->getAttributes($this->attributes).'>
        ';

		$html .= $this->suffix;
		
		return $html;
	}
}
?>
